package la.iok.hzsvn.lewin.movie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.service.*;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("UserFile")
public class UserFileController {

    private final UserFileService userFileService;

    public UserFileController(UserFileService userFileService) {
        this.userFileService = userFileService;
    }

    /**
     * 上传玩家头像
     * @param token 操作用户
     * @param id 用户id
     * @param file 玩家文件
     * @return 操作结果
     */
    @PostMapping("{id}/cover")
    public OperatorResponse cover(@RequestHeader Token token, @PathVariable Long id, MultipartFile file, String path){
        System.out.println("成功进入接口执行判断"+"Token="+token+"Id="+id+"File="+file+"Path="+path);
        userFileService.uploadCover(token,id,file,path);
        return OperatorResponses.success();
    }

    @GetMapping("{id}/cover")
    public void downloadCover(@RequestHeader Token token, HttpServletResponse response, @PathVariable Long id){
        userFileService.downloadFile(token,response,id);
    }
}